import request from '/@/utils/request';

/**
 * 以下为模拟接口地址，gitee 的不通，就换自己的真实接口地址
 *
 * （不建议写成 request.post(xxx)，因为这样 post 时，无法 params 与 data 同时传参）
 *
 * 后端控制菜单模拟json，路径在 https://gitee.com/lyt-top/vue-next-admin-images/tree/master/menu
 * 后端控制路由，isRequestRoutes 为 true，则开启后端控制路由
 * @method getAdminMenu 获取后端动态路由菜单(admin)
 * @method getTestMenu 获取后端动态路由菜单(test)
 */
export function useMenuApi() {
	return {
		viewMenu: (id: any) => {
			return request({
				url: `sys/menu/view/${id}`,
				method: 'GET',
			});
		},
		addMenu: (data: object) => {
			return request({
				url: '/sys/menu/create',
				method: 'post',
				data,
			});
		},
		updateMenu: (data: object) => {
			return request({
				url: 'sys/menu/update',
				method: 'put',
				data,
			});
		},
		getMenus: () => {
			// 根据角色查询菜单
			return request({
				url: 'sys/menu/list',
				method: 'GET',
			});
		},

		getTreeMenus: () => {
			return request({
				url: 'sys/menu/tree',
				method: 'GET',
			});
		},

		getSearchMenus: (data: object) => {
			return request({
				url: 'sys/menu/search',
				method: 'POST',
				data,
			});
		},
		deleteMenu: (id: any) => {
			return request({
				url: `sys/menu/delete/${id}`,
				method: 'DELETE',
			});
		},
		batchDelete: (data: object) => {
			return request({
				url: '/sys/menu/batchdelete',
				method: 'post',
				data,
			});
		},
	};
}
